package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.utils.UserContext;
import cn.wolfcode.trip.base.domain.Commodity;
import cn.wolfcode.trip.base.query.CommodityQueryObject;
import cn.wolfcode.trip.base.service.ICommodityService;
import cn.wolfcode.trip.base.service.IShopService;
import cn.wolfcode.trip.base.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/commodity")
public class CommodityController {
    @Autowired
    private ICommodityService commodityService;


    @GetMapping
    @ResponseBody
    public Object getCommends(@ModelAttribute("qo") CommodityQueryObject qo){
        return commodityService.query(qo);
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Object getproduct(@PathVariable Long id){
        return commodityService.getProduct(id);
    }

    //商品放进购物车
    @PutMapping("/{id}")
    @ResponseBody
    public Object update(@PathVariable Long id){
        JSONResult result = new JSONResult();

        try {
            commodityService.stateByid(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }

        return result;
    }

}
